<template>
	<view class="container">
		<block v-if="show">
		<view class="form-container">
			<view class="submit-form-group">
				<view class="form-row">
					<view class="left">转让类型</view>
					<view class="right">{{name}}</view>
				</view>
				<view class="form-row">
					<view class="left">拥有数量</view>
					<view class="right">{{user_money}}</view>
				</view>
				<view class="form-row">
					<view class="left">转让数量</view>
					<input type="text" placeholder="请输入转让数量" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.money" />
				</view>
				<view class="form-row">
					<view class="left">对方账号</view>
					<input type="text" placeholder="请输入对方账号" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.dfmobile" />
				</view>
				<view class="form-row">
					<view class="left">对方ID</view>
					<input type="text" placeholder="请输入对方ID" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.uid" />
				</view>
				<view class="form-row">
					<view class="left">交易密码</view>
					<input type="password" placeholder="请输入交易密码" placeholder-class="input-placeholder26" class="form-row-input" v-model="form.paypwd" />
				</view>
			</view>
			<button type="default" class="submit-btn" :disabled="btnDisabled" @click="tijiao">{{zr_text}}</button>
			<view class="hint">
				<view class="hint-tit">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/common/hint.png" mode="widthFix"></image>
					<text>温馨提示</text>
				</view>
				<view class="hint-con">
					{{name}}单次最小转让数量为{{g_min}}，最大为{{g_max}}；{{name}}转让数量必须为{{g_xishu}}的整数倍；{{name}}转让需扣除{{g_sxf}}%服务费
				</view>
			</view>
		</view>
		</block>
	</view>
</template>

<script>
	var validate = require("@/components/validate/validate.js");
	var _this;
	export default {
		data() {
			return {
				zr_text:'转让',
				zr_open:1,
				btnDisabled:false,
				show:false,
				name:'',
				user_money:0,
				g_min:0,
				g_max:0,
				g_xishu:0,
				g_sxf:0,
				form:{
					step:1,
					id:0,
					money:'',
					dfmobile:'',
					uid:'',
					paypwd:''
				},
			};
		},
		onNavigationBarButtonTap(e) {
			uni.navigateTo({
				url:`my-wallet-transfer-list??u_wid=${_this.form.id}`
			})
		},
		methods: {
			tijiao(){
				this.form.step = 2
				this.submit()
			},
			async submit() {
				if (this.form.step == 2) {
					var rule = [{
						// 字段名
						name: 'money',
						rules: ['require', 'number'],
						errorMsg: {
							require: '请输入转让数量',
							number: '转让数量只能为数字'
						}
					},{
						// 字段名
						name: 'dfmobile',
						rules: ['require', 'mobile'],
						errorMsg: {
							require: '请输入对方账号',
							mobile: '对方账号格式有误'
						}
					},{
						// 字段名
						name: 'uid',
						rules: ['require', 'number'],
						errorMsg: {
							require: '请输入对方ID',
							number: '对方ID只能为数字'
						}
					},{
						// 字段名
						name: 'paypwd',
						rules: ['require', 'min:6'],
						errorMsg: {
							require: '请输入交易密码',
							min: '交易密码最少6位'
						}
					}];
					// 是否全部通过，返回Boolean
					let checked = validate.check(this.form, rule);
					if (!checked) {
						// 获取错误信息
						let err = validate.getError();
						uni.$u.toast(err[0])
						return;
					}
					_this.btnDisabled=true
				}
				const data = await _this.$post('api/my_wallet_given',this.form)
				if (data.code == 200) {
					this.$u.toast(data.msg)
					this.form.step = 1
					this.submit()
					setTimeout(res=>{
						uni.navigateTo({
							url:'my-wallet-transfer-list'
						})
					},2000)
				} else if (data.code == 10) {
					this.show=true
					this.name = data.data.name
					this.user_money = data.data.user_money
					this.g_min = data.data.g_min
					this.g_max = data.data.g_max
					this.g_xishu = data.data.g_xishu
					this.g_sxf = data.data.g_sxf
				} else if (data.code == 50) {
					this.$u.toast(data.msg)
					setTimeout(res=>{
						uni.redirectTo({
							url:'/pages/center/paypwd'
						})
					},2000)
				}else {
					this.$u.toast(data.msg)
				}
				setTimeout(res=>{
					_this.btnDisabled=false
				},2000)
			}
		},
		onLoad(e) {
			_this = this;
			if(e.id){
				_this.form.id=e.id
			}
			_this.submit()
		},
		onShow() {

		},
		components: {}
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/form.scss";
	.container {
		padding: 0;
		.form-container{
			padding: 20rpx 30rpx 0 30rpx;
			.submit-form-group{
				padding: 0 30rpx;
			}
		}
	}
</style>